/* ===============================================================================
   Cygnus Innovation Ltd.
 * Designed By Md. Ataur Rahaman
 * 
 * 
 * Descripttion: This is the ....
// ==============================================================================*/


using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;

using Microsoft.ApplicationBlocks.Data;

namespace nplJobsDAL
{
    class DataBaseHelper: DataAccessBase
    {
        private SqlParameter[ ] _parameters;


        /// <summary>
        /// Costructor that helps to initialize with the procedure name.
        /// </summary>
        /// <param name="storedprocedurename"></param>
        public DataBaseHelper( string storedprocedurename )
		{
			StoredProcedureName = storedprocedurename;
		}


        /// <summary>
        /// Run the procedure(Inherited from Base) with the specific transaction
        /// </summary>
        /// <param name="transaction">Sql Transaction</param>
        public void Run( SqlTransaction transaction )
		{
			SqlHelper.ExecuteNonQuery( transaction , CommandType.StoredProcedure , StoredProcedureName , Parameters );
		}


        /// <summary>
        /// Run the procedure(Inherited from Base) with the specific transaction and required Parameters.
        /// </summary>
        /// <param name="transaction">Sql Transaction</param>
        /// <param name="parameters">Parameters that required by the procedure.</param>
        public void Run( SqlTransaction transaction , SqlParameter[] parameters )
		{
			SqlHelper.ExecuteNonQuery( transaction , CommandType.StoredProcedure , StoredProcedureName , parameters );
		}

        
        /// <summary>
        /// Run the procedure(Inherited from Base) with required Parameters And Specific Connection String.
        /// </summary>
        /// <param name="connectionstring">Connection string for the Database</param>
        /// <param name="parameters">Parameters that required by the procedure.</param>
        /// <returns> return type is System.Data.DataSet</returns>
		public DataSet Run( string connectionstring , SqlParameter[ ] parameters )
		{
			DataSet ds;
			ds = SqlHelper.ExecuteDataset( connectionstring , StoredProcedureName , parameters );
			return ds;
		}


        /// <summary>
        /// RunScalar the procedure(Inherited from Base). return type object.
        /// </summary>
        public object RunScalar()
        {           
            object obj;
            obj = SqlHelper.ExecuteScalar(base.ConnectionString, CommandType.StoredProcedure, StoredProcedureName, Parameters);
            return obj;
        }



        /// <summary>
        /// Call the procedure(Inherited from Base) for getting some scalar/single value. provide required Parameters And Specific Connection String.
        /// </summary>
        /// <param name="connectionstring">Connection string for the Database</param>
        /// <param name="parameters">Parameters that required by the procedure.</param>
        /// <returns>Return the scalar value as System.object type.</returns>
		public object RunScalar( string connectionstring , SqlParameter[ ] parameters )
		{
			object obj;
			obj = SqlHelper.ExecuteScalar( connectionstring , StoredProcedureName , parameters );
			return obj;
		}


        /// <summary>
        /// Run the procedure(Inherited from Base) with specified Transaction and SqlParameters list for getting Scalar onject.
        /// </summary>
        /// <param name="transaction">Sql Transaction</param>
        /// <param name="parameters">Parameters that required by the procedure.</param>
        /// <returns>Return the scalar value as System.object type.</returns>
		public object RunScalar( SqlTransaction transaction , SqlParameter[] parameters )
		{
			object obj;
			obj = SqlHelper.ExecuteScalar( transaction , StoredProcedureName , parameters );
			return obj;
		}


        /// <summary>
        /// Run the procedure(Inherited from Base) with specified connection string for getting Dataset.
        /// </summary>
        /// <param name="connectionstring">Connection string for the Database.</param>
        /// <returns>return System.Data.DataSet</returns>
		public DataSet Run( string connectionstring )
		{
			DataSet ds;
			ds = SqlHelper.ExecuteDataset( connectionstring , CommandType.StoredProcedure , StoredProcedureName );
			return ds;
		}

		
        /// <summary>
        /// Run the procedure(Inherited from Base). return type void.
        /// </summary>
        public void Run()
		{
			SqlHelper.ExecuteNonQuery( base.ConnectionString , CommandType.StoredProcedure , StoredProcedureName , Parameters );
		}


        /// <summary>
        /// Run the procedure(Inherited from Base) with the parameters list.
        /// </summary>
        /// <param name="parameters">Parameters that required by the procedure.</param>
        /// <returns>Return System.Data.SqlClient.SqlDataReader</returns>
		public SqlDataReader Run( SqlParameter[ ] parameters )
		{
			SqlDataReader dr;
			dr = SqlHelper.ExecuteReader( base.ConnectionString , CommandType.StoredProcedure , StoredProcedureName , parameters );
			return dr;
		}


        /// <summary>
        /// Get or Set the Parameters that required by procedure.
        /// </summary>
		public SqlParameter[ ] Parameters
		{
			get { return _parameters; }
			set { _parameters = value; }
		}
    }
}
